package com.manor.main.login;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentTransaction;

import com.manor.main.R;


public class BaseVerifyFragment extends Fragment {

    public static final String FLAG_CONTENT = "toolbarTitle";
    private int fromType;
    private String toolbarTitle;

    public BaseVerifyFragment() {

    }

    public static BaseVerifyFragment newInstance() {
        return new BaseVerifyFragment();
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Bundle arguments = getArguments();
        if (arguments != null) {
            fromType = arguments.getInt(VCodeVerifyFragment.FLAG_FROM_TYPE);
            toolbarTitle = arguments.getString(FLAG_CONTENT);
        }
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        return inflater.inflate(R.layout.fragment_register, container, false);
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        TextView tvTitle = view.findViewById(R.id.tv_title);
        tvTitle.setText(toolbarTitle);


        VCodeVerifyFragment vCodeVerifyFragment = (VCodeVerifyFragment) getChildFragmentManager().findFragmentByTag(VCodeVerifyFragment.class.getSimpleName());
        if (vCodeVerifyFragment == null) {
            vCodeVerifyFragment = VCodeVerifyFragment.newInstance();
        }

        Bundle bundle = new Bundle();
        bundle.putInt(VCodeVerifyFragment.FLAG_FROM_TYPE, fromType);
        bundle.putString(VCodeVerifyFragment.FLAG_TITLE_TEXT, "手机号码验证");
        bundle.putString(VCodeVerifyFragment.FLAG_INPUT_HINT, "请输入您的淘米平台手机号");
        bundle.putString(VCodeVerifyFragment.FLAG_BTN_TEXT, "下一步");
        vCodeVerifyFragment.setArguments(bundle);
        FragmentTransaction ft = getChildFragmentManager().beginTransaction();
        if (!vCodeVerifyFragment.isAdded()) {
            ft.add(R.id.fl_register_parent, vCodeVerifyFragment, SmsLoginFragment.class.getSimpleName());
            ft.addToBackStack(SmsLoginFragment.class.getSimpleName());
        } else {
            ft.show(vCodeVerifyFragment);
        }
        ft.commit();
    }
}